﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestDemo.aspx.cs" Inherits="Questionnaire_TestDemo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../JS/jsl.format.js" type="text/javascript"></script>
    <script src="../JS/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function jsonF(jsonVal, obj) {
            //alert(jsonVal);
            var jsVal = jsl.format.formatJson(jsonVal);
            $('#' + obj).val(jsVal);
        }
        function setTab(m, n) {

            var tli = document.getElementById("menu" + m).getElementsByTagName("li");

            var mli = document.getElementById("main" + m).getElementsByTagName("ul");

            for (i = 0; i < tli.length; i++) {

                tli[i].className = i == n ? "hover" : "";

                mli[i].style.display = i == n ? "block" : "none";

            }

        }

        ///获取短连接
        function GetShortUrl() {
            $.ajax({
                type: 'Post',
                url: 'QuestionnaireSetAjax.aspx?action=GetShortUrl',
                data: '&data='+$("#logURL").val(),
                complete: function (data) {
                    if (data.responseText != 'error' && data.responserText != '') {
                        $("#shortLogUrl").val(data.responseText)
                    }
                }
            });
        }


        ///获取问卷
        function GetQuestionnaireInfo() {
            $.ajax({
                type: 'Post',
                url: 'QuestionnaireSetAjax.aspx?action=GetQuestionnaireInfo',
                data:'&data=' + encodeURI($("#json_input").val()),
                complete: function (data) {
                    if (data.responseText != 'error' && data.responserText != '') {
                        jsonF(data.responseText, 'TextBox2');
                        var questionPaperInfo = JSON.parse(data.responseText);

                        var submitQuestionnaire = {};
                        submitQuestionnaire.SerialId = $("#serialId1").val();
                        submitQuestionnaire.MemberId = $("#menberId").val();
                        submitQuestionnaire.Key = $("#tocken").val();
                        submitQuestionnaire.FactorNo = "";
                        submitQuestionnaire.AnswerRecords = questionPaperInfo.AnswerRecords;

                        var jsonstr = JSON.stringify(submitQuestionnaire);
                        jsonF(jsonstr, 'Textarea2'); 
                    }
                }
            });
        }

        //提交问卷数据
        function submitQuestionnaireInfo() {
            $.ajax({
                type: 'Post',
                url: 'QuestionnaireSetAjax.aspx?action=AnswerTheQuestionList',
                data: '&data=' + encodeURI($("#Textarea2").val()),
                complete: function(data) {
                    if (data.responseText != 'error' && data.responserText != '') {
                        jsonF(data.responseText, 'Textarea3');
                    }
                }
            });
        }

        //生成获取套餐的请求json
        function GetRequestTC() {
            var requst = {};
            requst.QuestionSettingId = $("#QuestionSettingId").val();
            requst.Key = "<%=ModifyKey%>";
            jsonF(JSON.stringify(requst), 'requestTC');
        }
        //获取套餐的返回json
        function GetResposnTC() {
            $.ajax({
                type: 'Post',
                url: 'QuestionnaireSetAjax.aspx?action=GetQuestionPaperInfo',
                data:'&data=' + encodeURI($("#requestTC").val()),
                complete: function (data) {
                    if (data.responseText != 'error' && data.responserText != '') {
                        jsonF(data.responseText, 'resposnTC');
                    }
                }
            });
        }

        //更新套餐

        function UpdateTC() {

            var requst = {};
            requst.Key = "<%=ModifyKey%>";
            requst.QuestionPaperInfo = JSON.parse($("#resposnTC").val());
            $.ajax({
                type: 'Post',
                url: 'QuestionnaireSetAjax.aspx?action=SetQuestionPaperInfo',
                data:'&data=' + encodeURI(JSON.stringify(requst)),
                complete: function (data) {
                    if (data.responseText != 'error' && data.responserText != '') {
                        jsonF(data.responseText, 'Textarea1');
                    }
                }
            });
        }

        function openPage() {
            window.open("http://www.t.ly.com/scenery/zhuanti/blhealth" + $("#Text1").val());
        }
    </script>
    <style type="text/css">
        body,
        div,
        ul,
        li {
            margin: 0 auto;
            padding: 2px;
        }

        body {
            font: 14px "微软雅黑";
            /*text-align: center;*/
        }

        a:link {
            color: #00F;
            text-decoration: none;
        }

        a:visited {
            color: #00F;
            text-decoration: none;
        }

        a:hover {
            color: #c00;
            text-decoration: underline;
        }

        ul {
            list-style: none;
        }

        .main {
            clear: both;
            padding: 8px;
            /*text-align: center;*/
        }
        /*第一种形式*/

        #tabs0 {
            width: 1400px;
            border: 1px solid #cbcbcb;
            background-color: #f2f6fb;
        }

        .menu0 {
            width: 1400px;
        }

            .menu0 li {
                display: block;
                float: left;
                padding: 4px 0;
                width: 150px;
                text-align: center;
                cursor: pointer;
                background: #FFFFff;
            }

                .menu0 li.hover {
                    background: #f2f6fb;
                }

        #main0 ul {
            display: none;
        }

            #main0 ul.block {
                display: block;
            }
    </style>
</head>
<body>
    <form id="form1" runat="server">

        <div>
            <div id="tabs0">

                <ul class="menu0" id="menu0">

                    <li onclick="setTab(0,0)" class="hover">获取设置问卷套餐</li>

                    <li onclick="setTab(0,1)">获取提交答卷</li>
                </ul>

                <div class="main" id="main0">

                    <ul class="block">
                        <li>
                            <div>
                                <%--<input id="btn1" type="button" value="生成短链" onclick="GetShortUrl()"/><br/>
                                 长连接：<input id="logURL" type="text" value="http://www.ly.com" />
                                 短连接：<input id="shortLogUrl" type="text" value="" />--%>
                                <%--<br />--%>
                                问卷套餐流水号：<input id="QuestionSettingId" type="text" value="TW20161112181520422" />
                                <input id="btn1" type="button" value="生成获取套餐请求json" onclick="GetRequestTC()" /><br />
                                请求json：<br>
                                <textarea id="requestTC" rows="5" cols="100" spellcheck="false" runat="server"></textarea>
                                <div id="div3" runat="server"></div>
                            </div>
                            <br />
                            <input id="btn3" type="button" value="获取套餐" onclick="GetResposnTC()" /><br />
                            返回json或新生成的json：<br />
                            <textarea id="resposnTC" rows="10" cols="100" spellcheck="false" runat="server"></textarea>
                            <div id="div4" runat="server"></div>

                            <asp:Button ID="Button2" runat="server" Text="根据后台数据新生成一个套餐" OnClick="Button2_Click" />
                            <input id="btn2" type="button" value="更新获取的套餐" onclick="UpdateTC()" />
                            <br />
                            更新结果：<br />
                            <textarea id="Textarea1" rows="5" cols="100" spellcheck="false" runat="server"></textarea>
                            <div id="div5" runat="server"></div>
                        </li>
                    </ul>

                    <ul>
                        <li>        流水号：<input id="txtSerialId"  runat="server" type="text" value="sz57fud50421015u536085540" /><br/>
                            会员ID：<input id="txtMemberId1" runat="server" type="text" value="95232354"/><br/>

                            <asp:Button ID="Button3" runat="server" Text="生成请求json" OnClick="Button3_Click"/>
                            <br/>
                             页面参数：<input id="Text1"  runat="server" type="text" value=""  style="width: 300px;"/>
                             <input id="Button1" type="button" value="打开页面" onclick="openPage()" /><br/>
                            请求json：<br />
                            <textarea id="json_input" rows="5" cols="100" spellcheck="false" runat="server"></textarea>
                            <div id="div1" runat="server"></div>
                            <br />
                            <input id="Button1" type="button" value="获取答卷" onclick="GetQuestionnaireInfo()" />
                            <br />
                            返回json：<br />
                            <textarea id="TextBox2" rows="15" cols="100" spellcheck="false" runat="server"></textarea>
                            <div id="div2" runat="server"></div>
                            <br />
                              答案文本：<br />
                            <textarea id="Textarea2" rows="15" cols="100" spellcheck="false" runat="server"></textarea>
                            <div id="div6" runat="server"></div>

                             <input id="Button1" type="button" value="提交答卷" onclick="submitQuestionnaireInfo()" />
                            <br/>

提交答案返回json：<br />
                            <textarea id="Textarea3" rows="5" cols="100" spellcheck="false" runat="server"></textarea>
                            <div id="div7" runat="server"></div>
                            <br />                        </li>
                        <input id="menberId" type="hidden" runat="server" />
                        <input id="serialId1" type="hidden" runat="server" />
                        <input id="tocken" type="hidden" runat="server" />
                    </ul>

                </div>

            </div>
        </div>
    </form>
</body>
</html>
